import { Mutation, Action } from 'vuex'
export interface StateType {
  tagsView: boolean;
  fixedHeader: boolean;
  sidebarLogo: boolean;
}

export interface ModuleType {
  namespaced: boolean;
  state: StateType;
  mutations: {
    CHANGE_SETTING: Mutation<StateType>;
  };
  actions: {
    changeSetting: Action<StateType, StateType>;
  };
}

const storeModel: ModuleType = {
  namespaced: true,
  state: {
    tagsView: true,
    fixedHeader: false,
    sidebarLogo: true
  },
  mutations: {
    CHANGE_SETTING: (state, { key, value }) => {
      if (Object.prototype.hasOwnProperty.call(state, key)) {
        (state as any)[key] = value
      }
    }
  },
  actions: {
    changeSetting({ commit }, data) {
      commit('CHANGE_SETTING', data)
    }
  }
}

export default storeModel
